﻿using System;
using System.Drawing;

namespace MarioMapEditor
{
    class ObAcEnemy2 :ObActive
    {
        public enum ENERMY2 { MOB01 = 70, MOB02, MOB03, SNAIL, RUBY, SQUID, FISH01, FISH02 };

        public ObAcEnemy2(){
            ID      = 0;
            Info    = (int)INFO.LEFT;
            Width   = 1;
            Height  = 1;
        }

        public ObAcEnemy2(ENERMY2 nid)
        {
            ID = (int)nid;
            Info = (int)INFO.LEFT;
            Width = 1;
            Height = 1;
        }

        public override bool SetID(int nID)
        {
            if (checkType(nID))
            {
                ID = nID;
                return true;
            }
            return false;
        }

        public override bool SetINFO(int nInfo)
        {
            if (Enum.IsDefined(typeof(INFO), nInfo))
            {
                Info = nInfo;
                return true;
            }
            return false;
        }

        public static bool checkType(int objectID)
        {
            if (Enum.IsDefined(typeof(ENERMY2), objectID))
            {
                return true;
            }
            return false;
        }

        public static int selectEnermy(int x, int y)
        {
            switch (x)
            {
                case 0:
                    switch (y)
                    {
                        case 0:
                            return (int)ENERMY2.MOB01;
                        case 1:
                            return (int)ENERMY2.MOB02;
                        case 2:
                            return (int)ENERMY2.MOB03;
                    }
                    break;
                case 1:
                    switch (y)
                    {
                        case 0:
                            return (int)ENERMY2.SNAIL;
                        case 1:
                            return (int)ENERMY2.RUBY;
                        case 2:
                            return (int)ENERMY2.SQUID;
                    }
                    break;
                case 2:
                    switch (y)
                    {
                        case 0:
                            return (int)ENERMY2.FISH01;
                        case 1:
                            return (int)ENERMY2.FISH02;
                        case 2:
                            return 0;
                    }
                    break;
            }
            return 0;
        }
        public override Bitmap GetBitmap()
        {
            if (!checkType(ID))
            {
                return null;
            }
            var cropRect = new Rectangle(0, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
            switch (ID)
            {
                case (int)ENERMY2.MOB01:
                    cropRect = new Rectangle(0, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY2.SNAIL:
                    cropRect = new Rectangle(MainForm.FileSize, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY2.FISH01:
                    cropRect = new Rectangle(MainForm.FileSize * 2, 0, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY2.MOB02:
                    cropRect = new Rectangle(0, MainForm.FileSize, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY2.RUBY:
                    cropRect = new Rectangle(MainForm.FileSize, MainForm.FileSize, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY2.FISH02:
                    cropRect = new Rectangle(MainForm.FileSize * 2, MainForm.FileSize, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY2.MOB03:
                    cropRect = new Rectangle(0, MainForm.FileSize * 2, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
                case (int)ENERMY2.SQUID:
                    cropRect = new Rectangle(MainForm.FileSize, MainForm.FileSize * 2, MainForm.FileSize * Width, MainForm.FileSize * Height);
                    break;
            }

            var src = Properties.Resources.Enermy2;
            var trg = new Bitmap(Width * MainForm.TileSize, Height * MainForm.TileSize);
            using (var g = Graphics.FromImage(trg))
            {
                g.DrawImage(src, new Rectangle(0, 0, trg.Width, trg.Height), cropRect, GraphicsUnit.Pixel);
            }
            return trg;
        }
    }
}
